//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#if _MSC_VER > 1000
#pragma once
#endif

#ifndef __GHOST_SHAREDMEMORY_H__
#define __GHOST_SHAREDMEMORY_H__

#include <elasys_server.h>
#include <interlocked.h>
#include "ghost.h"

class CGhostSharedMemory: publicGhost
{
public:
    UInt32 AddRef();
    UInt32 Release();

public:
    CGhostSharedMemory() : m_hSharedMemory(NULL) {}
    virtual ~CGhostSharedMemory();

    ECode Initialize(
        /* [in] */ WString name,
        /* [in] */ MemorySize size,
        /* [in] */ Boolean bCommit);

private:
    PVoid m_hSharedMemory;
private:
    Interlocked m_nRefs;
};

class CGhostSharedMemoryFactory: public GhostFactory
{
public:
    ECode CreateGhost(
        /* [out] */ Ghost ** ppGhost,
        /* [out] */ Boolean * pbExisted);

public:
    CGhostSharedMemoryFactory(
        /* [in] */ WString name,
        /* [in] */ MemorySize size,
        /* [in] */ Boolean bCommit)
        : GhostFactory(name, ObjectType_SharedMemory),
          m_size(size),
          m_bCommit(bCommit) {}

private:
    MemorySize m_size;
    Boolean    m_bCommit;
};

#endif //__GHOST_SHAREDMEMORY_H__
